/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package miage.sessions.persistant;

import java.rmi.RemoteException;
import java.util.Date;
import java.util.List;
import javax.ejb.FinderException;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;
import miage.beans.FacturePresentation;
import miage.entities.Client;
import miage.entities.Facture;

/**
 *
 * @author Pepito
 */
@Stateless
public class FactureFacade implements FactureFacadeLocal {
    @PersistenceContext
    private EntityManager em;
    
    private AccountClientFacade client;
    
    @Override
    public Facture getFacture(int id_facture, String login) throws FinderException, RemoteException{
        return (Facture) em.createNamedQuery("Facture.findByIdFactureLogin").setParameter("idFacture", id_facture).setParameter("acheteur", login).getSingleResult();
    }

    @Override
    public List<Facture> getAllFactureDuClient(String login) throws FinderException, RemoteException {
        System.out.println("facture du client en cours.");
        System.out.println("client client : "+login.toString()+" aoui");
        return (List<Facture>) em.createNamedQuery("Facture.findByClientCommande").setParameter("clientCommande", login).getResultList();
    }

    @Override
    public List<Facture> getAllFactureBetweenToDateByClient(Date dateDebut, Date dateFin, String login) throws FinderException, RemoteException {
        return null;//(List<Facture>) em.createNamedQuery("Facture.findAllBetweenToDateByClient").setParameter("date", dateDebut).setParameter("date", dateFin).setParameter("acheteur", login).getResultList();
    }
    @Override
    public void addFacture(FacturePresentation laFacture){
     /*         
        System.out.println("persistance de la facture en cours...");
        em.persist(laFacture);
        System.out.println("persist ok fini add facture ok");*/
    }

    @Override
    public Facture getFactureByClientDate(String login, Date date) throws FinderException, RemoteException {
        return (Facture) em.createNamedQuery("Facture.findByClientDate").setParameter("acheteur", login).setParameter("date", date).getSingleResult();
    }

    @Override
    public void addUneFacture(Facture facture) {
        System.out.println("dans facture");
        em.persist(facture);
        System.out.println("add ok");
    }
}
